package cn.tedu.fresheveryday.mapper;

import cn.tedu.fresheveryday.pojo.entity.OrderDistribution;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

@Repository
public interface OrderDistributionMapper {
    /**
     * 添加配送信息
     * @param distribution
     * @return
     */
    void insert(OrderDistribution distribution);

    /**
     * 通过id删除订单配送信息
     * @param id
     */
    @Delete("delete from order_distribution where id = #{id}")
    void deleteById(String id);

    /**
     * 通过id修改配送信息
     * @param distribution
     * @return
     */
    void updateById(OrderDistribution distribution);

    /**
     * 通过订单id查询配送信息
     * @param orderId
     * @return
     */
    @Select(
            "select id, receiver, phone, address, note from order_distribution " +
            "where id = (" +
                "select dist_id from product_order " +
                "where id = #{orderId}" +
            ")"
    )
    OrderDistribution selectByOrderId(int orderId);
}